Secure computer code, such as JAVA, from SUN MICROSYSTEMS, INC., Mountain View, California, requires that all accesses to an array be checked to insure that the programmed code does not access prohibited memory spaces. An attempt to access a prohibited memory space must be trapped to insure computer security.
Array bounds checking of computer code can be appreciated with reference to an example associated with the JAVA programming language. Arrays are special types in JAVA. Arrays are used to keep similar information in the same place. Arrays hold a list of objects that can be referenced by indexing. For example, to create an array "a" of ten integers, the following code is used: "int a[]=new int [10]". Individual variables in the array are referenced by a number, for example, a[0], a[1], through a[9]. Note that the subscripts go from zero, the first element in the array, to the size of the array minus one.
Now suppose that a subsequent source code instruction states: "a[12]=4". This instruction attempts to load the value "4" into the twelfth position of the array "a". When the foregoing code is processed by a JAVA compiler, the JAVA compiler will perform a run-time bounds check. This bounds check requires the execution of several instructions. This processing is computationally expensive, especially when the array is in a loop. When the JAVA compiler identifies the foregoing bounds error, it will generate a message and subsequently prohibit processing of the source code.
In view of the foregoing, it would be highly desirable to reduce the array bounds processing burden on a compiler by providing a hardware based technique for array bound checking. Such a technique should be easy to implement. Ideally, such a technique would be controllable through existing software instructions. Thus, the compiler would not be required to process a new class of instructions.